package com.example.module_mine.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_image.GlideApp
import com.example.module_mine.R
import com.example.module_mine.login.loginnet.MineModel

class MineAdapter : RecyclerView.Adapter<MineAdapter.MineViewHolder>() {
    private var list = mutableListOf<MineModel>()

    fun setData(list: MutableList<MineModel>) {
        this.list.clear()
        this.list = list
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MineViewHolder {
        return MineViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_mine, parent, false)
        )
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: MineViewHolder, position: Int) {
        GlideApp.with(holder.itemView.context)
            .load(list[position].img)
            .into(holder.item_iv)
        holder.item_tv.text=list[position].name
        holder.itemView.setOnClickListener {
            when(list[position].name){
                "我的申请"->{
                    ARouter.getInstance().build("/module_mine/MyapplyActivity").navigation()
                }
                "我的审核"->{
                    ARouter.getInstance().build("/module_mine/MyapplyDetailActivity").navigation()
                }
            }
        }
    }


    inner class MineViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        lateinit var item_iv: ImageView
        lateinit var item_tv: TextView

        init {
            item_iv = itemView.findViewById(R.id.item_iv)
            item_tv = itemView.findViewById(R.id.item_tv)
            item_iv.setOnClickListener {
                when (position) {
                    0 -> {

                    }

                    2 -> {
                        ARouter.getInstance().build("/module_mine/GongGaoActivity").navigation()
                    }

                    3 -> {
                        ARouter.getInstance().build("/mine/peopleActivity").navigation()

                    }

                    4 -> {
                        ARouter.getInstance().build("/vip/VipActivity").navigation()
                    }
                    5->{
                        ARouter.getInstance().build("/module_mine/WuYeActivity").navigation()
                    }
                }
            }
        }
    }
}
